package collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class IteratorDemo {
    public static void main(String[] args) {
        Collection<String> c=new ArrayList<>();
        c.add("one");
        c.add("#");
        c.add("two");
        c.add("#");
        c.add("three");
        c.add("#");
        c.add("four");
        c.add("#");
        c.add("five");
        System.out.println(c);

        Iterator<String> it=c.iterator();
        while (it.hasNext()){//看是否还有下一个元素,如果有就返回true,否则返回false
            String e= it.next();//获取下一个元素
            System.out.println(e);
            if ("#".equals(e)){
                it.remove();
                //c.remove(e);
            }
        }
        System.out.println(c);

    }
}
